<?php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller {

    public function login(){
        $this->display();
    }
     public function code(){
        $Verify=new  \Think\Verify();
        $Verify->entry();
    }
    public function dologin(){
    if(IS_POST)
        {
            $rst=$this->checkcode(I('post.code'));
            if($rst===false)
                $this->error('验证码错误');
            $username=I('post.username');
            $password=I('post.password');
            $user=M("tuser");
            $userdata=$user->where("username='$username'")->find();
            if($userdata!=NULL)
            {
                $md5password=md5($password);
                if($md5password==$userdata['password'])
            {
                session('loginname',$username);
                $this->success('登陆成功，请稍等！',U('admin/index/index'));
            }
            else 
            {
                $this->error('登录失败，用户名或密码错误！');
            }
            }
             else
            {
                $this->error('登录失败，用户名或密码错误！');
             }

        }
    }
    public function checkcode($code,$codeid=''){
        $Verify=new  \Think\Verify();
        return $Verify->check($code,$codeid);
    }
    public function logout(){
        session('[destroy]');
        $this->success("退出成功！",U("admin/Login/login"));
    }
}